<?php
session_start();
$user=isset ($_SESSION["user"])?$_SESSION["user"]:null;
if(!$user){
            echo "未登录，请先登录<a href='login.html'>登录</a>"; 
}else{
        //$id
        $title = $_POST["Title"];
        $content = $_POST["Content"];
        $createTime = (new DateTime())->format('Y-m-d H:i:s');
        $updateTime = $createTime;
        $authorId = $user["Id"];
        $authorName = $user["Username"];

        $sql="INSERT INTO `article`
        (`Title`,`Content`,`CreateTime`,`UpdateTime`,`AuthorId`,`AuthorName`)
        VALUES ('$title','$content','$createTime','$updateTime','$authorId','$authorName')";
        echo $sql;
        $conn = new mysqli("localhost",'root','',"myblog");
        $conn->query($sql);
        if($conn->error)
         echo $conn->error;
        else echo "新增文章成功!";
    
}
?>